
package com.jf.cloud.multishop.controller.platform;

import com.jf.cloud.common.constant.Constant;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.exception.LuckException;
import com.jf.cloud.common.response.ResponseEnum;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.multishop.dto.ShopCompanyAuditingDTO;
import com.jf.cloud.multishop.service.CompanyAuditingService;
import com.jf.cloud.multishop.vo.ShopCompanyAuditingVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Objects;

/**
 * @author zz
 * @date 2022/9/14 14:32
 */
@RestController("platformCompanyAuditingController")
@RequestMapping("/p/shop_company_auditing")
@Tag(name = "platform-审核店铺工商信息")
public class CompanyAuditingController {

    @Autowired
    private CompanyAuditingService companyAuditingService;

    @GetMapping("/page")
    @Operation(summary = "分页获取待审核的工商信息" , description = "分页获取待审核的工商信息")
    public ServerResponseEntity<PageVO<ShopCompanyAuditingVO>> getCompanyAuditingPage(PageDTO pageDTO, ShopCompanyAuditingDTO shopCompanyAuditingDTO) {
        if (!Objects.equals(Constant.PLATFORM_SHOP_ID, AuthUserContext.get().getTenantId())) {
            throw new LuckException(ResponseEnum.UNAUTHORIZED);
        }
        return ServerResponseEntity.success(companyAuditingService.page(pageDTO, shopCompanyAuditingDTO));

    }

    @PutMapping("/audit")
    @Operation(summary = "审核签约信息" , description = "审核签约信息")
    public ServerResponseEntity<Void> audit(@Valid @RequestBody ShopCompanyAuditingDTO shopCompanyAuditingDTO) {
        if (!Objects.equals(Constant.PLATFORM_SHOP_ID, AuthUserContext.get().getTenantId())) {
            throw new LuckException(ResponseEnum.UNAUTHORIZED);
        }
        shopCompanyAuditingDTO.setAuditorId(AuthUserContext.get().getUserId());
        companyAuditingService.audit(shopCompanyAuditingDTO);
        return ServerResponseEntity.success();
    }
}
